package com.yanqu.road.dao.impl.log;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.db.DbParameter;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.log.LogTitleUpgradeBuilding;

import java.sql.Timestamp;
import java.sql.Types;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class LogTitleUpgradeBuildingDaoImpl extends TempDao {

	public boolean addLogTitleUpgradeBuildingList(List<LogTitleUpgradeBuilding> list) {
		boolean result = false;
		getDb().setConnName(DbNameStrategy.getLogDb());
		String sql = "INSERT INTO t_l_title_upgrade_building(userId,vipExp,useTime,oldTitleId,prestige,earnSpeed,passId,estateFloor,mainTaskId,childCount,"
				+ "childEarn,heartCount,hasMonthCard,hasYearCard,buildingData,time) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
		List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
		for (LogTitleUpgradeBuilding data : list) {
			Map<Integer, DbParameter> para = new HashMap<>();
			int i = 1;
			para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
			para.put(i++, new DbParameter(Types.BIGINT, data.getVipExp()));
			para.put(i++, new DbParameter(Types.BIGINT, data.getUseTime()));
			para.put(i++, new DbParameter(Types.INTEGER, data.getOldTitleId()));
			para.put(i++, new DbParameter(Types.VARCHAR, data.getPrestige().toString()));
			para.put(i++, new DbParameter(Types.VARCHAR, data.getEarnSpeed().toString()));
			para.put(i++, new DbParameter(Types.INTEGER, data.getPassId()));
			para.put(i++, new DbParameter(Types.INTEGER, data.getEstateFloor()));
			para.put(i++, new DbParameter(Types.INTEGER, data.getMainTaskId()));
			para.put(i++, new DbParameter(Types.BIGINT, data.getChildCount()));
			para.put(i++, new DbParameter(Types.VARCHAR, data.getChildEarn().toString()));
			para.put(i++, new DbParameter(Types.INTEGER, data.getHeartCount()));
			para.put(i++, new DbParameter(Types.BOOLEAN, data.isHasMonthCard()));
			para.put(i++, new DbParameter(Types.BOOLEAN, data.isHasYearCard()));
			para.put(i++, new DbParameter(Types.VARCHAR, data.getBuildingData()));
			para.put(i++, new DbParameter(Types.TIMESTAMP, new Timestamp(data.getTime())));
			mapList.add(para);
		}

		if (getDb().executeBatchQuery(sql, mapList) > -1) {
			result = true;
		}
		return result;
	}
}
